const {
  wechatUploadFile,
  wechatDeleteFile,
  adminUploadFile,
  adminDeleteFile,
} = require('../../controllers/common/uploadFiles')
const {
  wechatCount,
  commonAdminHomeCount,
  commonMonitor,
} = require('../../controllers/common')
const logs = require('./logs.js')

const { verifyToken } = require('../../utils/jwt.js')

const commonRoutes = (fastify, options, done) => {
  /**
   * 图片 上传
   */
  fastify.post('/common/upload', { preHandler: verifyToken }, adminUploadFile)
  done()

  /**
   * 后台 图片删除
   */
  fastify.delete('/admin/upload', { preHandler: verifyToken }, adminDeleteFile)
  done()

  /**
   * 微信 维修单详情 图片 上传
   */
  fastify.post('/wechat/upload', wechatUploadFile)
  done()

  /**
   * 微信 维修单详情 图片 删除
   */
  fastify.delete('/wechat/upload', wechatDeleteFile)
  done()

  /**
   * 获取 服务订单统计
   */
  fastify.get('/common/wechat/count', { preHandler: verifyToken }, wechatCount)
  done()
  /**
   * 日志管理
   */
  fastify.register(logs)
  done()
  fastify.post(
    '/common/wechat/monitor',
    { preHandler: verifyToken },
    wechatCount
  )
  done()

  /**
   * 获取 管理台 首页 统计
   */
  fastify.get(
    '/common/admin/home',
    // { preHandler: verifyToken },
    commonAdminHomeCount
  )
  done()
}

module.exports = commonRoutes
